package com.hksj.Intelligentmanagement.controller;

import com.hksj.Intelligentmanagement.common.Result;
import com.hksj.Intelligentmanagement.dto.DeviceDTO;
import com.hksj.Intelligentmanagement.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/device")
@Api(tags = "设备管理")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    /**
     * 请求映射路径对应的方法不要重复,例如新增设备的映射路径为/api/device/create 对应的方法为create.
     * 而新增网关为/api/gateway/create 对应的方法不要也取名为create
     */
    @ApiOperation("新增设备")
    @PostMapping("/createDevice")
    public Result createDevice(@RequestBody DeviceDTO deviceDTO){
        return deviceService.createDevice(deviceDTO);
    }

    @ApiOperation("修改设备")
    @PutMapping("/updateDevice")
    public Result updateDevice(@RequestBody DeviceDTO deviceDTO){
        return deviceService.updateDevice(deviceDTO);
    }

    @ApiOperation("删除设备")
    @DeleteMapping("/deleteDevice/{id}")
    public Result deleteDevice(@PathVariable("id") String id){
        return deviceService.deleteDevice(id);
    }

    @ApiOperation("分页查询所有设备")
    @PostMapping("/queryDeviceListByPage")
    public Result queryDeviceListByPage(@RequestBody DeviceDTO deviceDTO){
        return Result.ok(deviceService.queryDeviceListByPage(deviceDTO));
    }

    @ApiOperation("通过设备id查询设备信息")
    @GetMapping("/queryDeviceByDeviceId/{deviceId}")
    public Result queryDeviceByDeviceId(@PathVariable("deviceId") String deviceId){
        return deviceService.queryDeviceByDeviceId(deviceId);
    }
}
